package fatboy.addons;
import fatboy.communication.ObjectID;
import fatboy.communication.Location;
import fatboy.communication.RemoteLocation;
import fatboy.communication.Command;
import fatboy.communication.ResidentDatabase;
import java.io.IOException;
import java.io.Serializable;
public class ProxyBroadcast extends Broadcast implements Serializable{
	private ObjectID id;
	private static final long serialVersionUID = 2159800065695342256L;
	public ProxyBroadcast(ObjectID other){
		super();
		id = new ObjectID(other);
	}
	private static Object createCommand(ObjectID idIn, String meth, Class<Object>[] types,
		Object[] params, boolean returns, Location location){
		Object result = null;
		try {
			Command cmd = new Command(idIn,meth,types,params,
			ProxyBroadcast.class.getSuperclass());
			location.sendCommand(cmd);
			result = location.recieveReturn();
			location.close();
		} catch (IOException e) {
			e.printStackTrace();
			} catch (SecurityException e) {
			e.printStackTrace();
			}catch (ClassNotFoundException e) {
			e.printStackTrace();
			}
			return result;
	}
	public Object writeReplace(){
		return this;
	}
	public Object readResolve(){
		if(getLocation(this.id).isHere()){
			return ResidentDatabase.getObject(id);
		}
		return this;
	}
public Location getLocation(ObjectID id) {
	return new RemoteLocation((ObjectID)id);
	}

	public void setId(fatboy.communication.ObjectID param1){
		String meth = "setId";
		Class[] types ={
			fatboy.communication.ObjectID.class
			};
		Object[] params = {
			param1
			};
		createCommand(id,meth,types,params,false, getLocation(id));
	}
	public void visit(fatboy.hypeerweb.Node param1, java.lang.Object param2){
		String meth = "visit";
		Class[] types ={
			fatboy.hypeerweb.Node.class,
			java.lang.Object.class
			};
		Object[] params = {
			param1,
			param2
			};
		createCommand(id,meth,types,params,false, getLocation(id));
	}
	protected void incBroadcastTotal(){
		String meth = "incBroadcastTotal";
		Class[] types ={

			};
		Object[] params = {

			};
		createCommand(id,meth,types,params,false, getLocation(id));
	}
	protected boolean broadcast(fatboy.hypeerweb.Node param1, fatboy.hypeerweb.Node param2){
		Object ret = null;
		String meth = "broadcast";
		Class[] types ={
			fatboy.hypeerweb.Node.class,
			fatboy.hypeerweb.Node.class
			};
		Object[] params = {
			param1,
			param2
			};
		ret = createCommand(id,meth,types,params,true, getLocation(id));
		return (Boolean)ret;
	}
	protected java.util.List getBroadcastList(fatboy.hypeerweb.Node param1, fatboy.hypeerweb.NodeAddress param2){
		Object ret = null;
		String meth = "getBroadcastList";
		Class[] types ={
			fatboy.hypeerweb.Node.class,
			fatboy.hypeerweb.NodeAddress.class
			};
		Object[] params = {
			param1,
			param2
			};
		ret = createCommand(id,meth,types,params,true, getLocation(id));
		return (java.util.List)ret;
	}
	public int getBroadcastTotal(){
		Object ret = null;
		String meth = "getBroadcastTotal";
		Class[] types ={

			};
		Object[] params = {

			};
		ret = createCommand(id,meth,types,params,true, getLocation(id));
		return (Integer)ret;
	}
	public boolean unitTests(java.util.List param1){
		Object ret = null;
		String meth = "unitTests";
		Class[] types ={
			java.util.List.class
			};
		Object[] params = {
			param1
			};
		ret = createCommand(id,meth,types,params,true, getLocation(id));
		return (Boolean)ret;
	}
	public fatboy.communication.ObjectID getId(){
		Object ret = null;
		String meth = "getId";
		Class[] types ={

			};
		Object[] params = {

			};
		ret = createCommand(id,meth,types,params,true, getLocation(id));
		return (fatboy.communication.ObjectID)ret;
	}
}

